﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Homebrew_SD_Manager
{
    public partial class BootMii : Form
    {
        public BootMii()
        {
            InitializeComponent();
        }

        private void BootMii_Load(object sender, EventArgs e)
        {
            if (Directory.Exists("bootmii"))
            {
                groupBox1.Enabled = true;
                checkBox1.Checked = true;
            }
            else
            {
                groupBox1.Enabled = false;
                checkBox1.Checked = false;
            }
            init_back(Homebrew_SD_Manager.Properties.Settings.Default.SettingBackColor);
            init_fore(Homebrew_SD_Manager.Properties.Settings.Default.SettingForeColor);
        }

        private void init_back(int color)
        {
            if (color != 0)
            {
                BackColor = Color.FromArgb(color);
                cbAutoboot.BackColor = Color.FromArgb(color);
                cbDelay.BackColor = Color.FromArgb(color);
                cbVideo.BackColor = Color.FromArgb(color);
                btSave.BackColor = Color.FromArgb(color);
            }
        }

        private void init_fore(int color)
        {
            if (color != 0)
            {
                ForeColor = Color.FromArgb(color);
                cbAutoboot.ForeColor = Color.FromArgb(color);
                cbDelay.ForeColor = Color.FromArgb(color);
                cbVideo.ForeColor = Color.FromArgb(color);
                btSave.ForeColor = Color.FromArgb(color);
            }
        }

        private void btSave_Click(object sender, EventArgs e)
        {
            if (checkBox1.Checked)
            {
                if (Directory.Exists("~bootmii"))
                    Directory.Move("~bootmii", "bootmii");

                File.Delete(@"bootmii/bootmii.ini");
                StreamWriter sw = new StreamWriter(@"bootmii/bootmii.ini", true);

                sw.WriteLine("# BootMii config file");

                sw.WriteLine("# Video mode, possible settings:");
                sw.WriteLine("# NTSC, PAL50, PAL60, PROGRESSIVE");
                sw.WriteLine("VIDEO=" + cbVideo.Text);
                sw.WriteLine("");
                sw.WriteLine("# Autoboot, possible settings:");
                sw.WriteLine("# SYSMENU, HBC");
                sw.WriteLine("AUTOBOOT=" + cbAutoboot.Text.Split('(')[1].Split(')')[0]);
                sw.WriteLine("");
                sw.WriteLine("# Autoboot delay, in seconds:");
                sw.WriteLine("# Default is 5");
                sw.WriteLine("BOOTDELAY=" + cbDelay.Text);
                sw.Flush();
                sw.Close();
            }
            else
            {
                if (Directory.Exists("bootmii"))
                    Directory.Move("bootmii", "~bootmii");
            }
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked == true)
                groupBox1.Enabled = true;
            else
                groupBox1.Enabled = false;
        }
    }
}
